package com.springboot.study.tests.genericity;

import com.alibaba.fastjson.JSON;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

public abstract class Feature implements Serializable {

    private static final long serialVersionUID = -5686942946661004151L;

    protected Map<String, Object> featureToMap = new HashMap<>();

    @Override
    public String toString() {
        return JSON.toJSONString(featureToMap);
    }


    protected Object getFeature(FeatureKey featureKey) {
        return featureToMap.get(featureKey.getCode());
    }

    protected void set(FeatureKey featureKey, Object val, Consumer<String> consumer) {
        if (null == val) {
            return;
        }
        featureToMap.put(featureKey.getCode(), val);
        consumer.accept(this.toString());
    }


}
